const fs = require('fs')
const util = require('util')
const readAsync = util.promisify(fs.readFile)

/* fs.readFile('./package.json', (err, data) => {
  if (err)
    return console.log(err)
  data = JSON.parse(data)
  console.log(data.name)
}) */
/* 
function readFileAsync(path) {
  return new Promise((resolve, reject) => {
    fs.readFile(path, (err, data) => {
      if (err)
        reject(err)
      else
        resolve(data)
    })
  })
}

readFileAsync('./package.json')
  .then(data => {
    data = JSON.parse(data)
    console.log(data.name)
  })
  .catch(err => {
    console.log(err)
  }) */

/* 
const util = require('util')

util.promisify(fs.readFile)('./package.json')
  .then(JSON.parse)
  .then(data => console.log(data.name))
  .catch(error => console.log(error))
 */

async function init(path) {
  try {
    let data = await readAsync(path)

    data = JSON.parse(data)
    
    console.log(data.name)
  } catch (err) {
    console.log(err)
  }
}

init('./package.json')
